home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Misc / Wood.0.72 / Sources / HitPath.m < prev    next >
Encoding:
Text File  |  1993-04-26  |  1.8 KB  |  87 lines

  1.  
  2.  
  3. #import "HitPath.h"
  4. #import "PSWUPath.h"
  5.  
  6. @implementation HitPath
  7.  
  8. static float officialHitWidth;
  9.  
  10. //************************************************************************
  11. // creating and destroying
  12.  
  13. + initialize
  14. {
  15.    if(self == [HitPath class])
  16.          officialHitWidth = 4.0;
  17.    return self;
  18. }
  19.  
  20. - init
  21. {  
  22.    [super initCountParams:8 countOps:4];
  23.    [self resetFill];
  24.         [self moveto:0 :0];
  25.         [self rlineto:0 :0];
  26.         [self rlineto:0 :0];
  27.         [self rlineto:0 :0];
  28.    [self closepath];
  29.    hitWidth = officialHitWidth;
  30.    return self;
  31. }
  32.    
  33. //************************************************************************
  34. // misc
  35.  
  36. - movePathToPoint:(const NXPoint *)p
  37. {
  38.    bbox[0] = floor(p->x - hitWidth / 2);
  39.    bbox[1] = floor(p->y - hitWidth / 2);
  40.    bbox[2] = ceil(p->x + hitWidth / 2);
  41.    bbox[3] = ceil(p->y + hitWidth / 2);
  42.    params[0] = p->x - hitWidth / 2;
  43.    params[1] = p->y - hitWidth / 2;
  44.    params[3] = hitWidth;
  45.    params[4] = hitWidth;
  46.    params[7] = - hitWidth;
  47.    return self;
  48. }
  49.  
  50. - (BOOL)hitPathStroke:(UPath *)aPath
  51. {
  52.    int hit;
  53.    
  54.    PSWHitStroke(bboxParams,sizeParams + 4,bboxOps,sizeOps + 2,
  55.    aPath->bboxParams,aPath->sizeParams + 4,aPath->bboxOps,aPath->sizeOps + 2,&hit);
  56.    return (BOOL)hit;
  57. }
  58.  
  59. - (BOOL)hitPathFill:(UPath *)aPath
  60. {
  61.    int hit;
  62.  
  63.    PSWHitFill(bboxParams,sizeParams + 4,bboxOps,sizeOps + 2,
  64.    aPath->bboxParams,aPath->sizeParams + 4,aPath->bboxOps,aPath->sizeOps + 2,&hit);
  65.    return (BOOL)hit;
  66. }
  67.  
  68. - awake
  69. {
  70.    [super awake];
  71.    hitWidth = officialHitWidth;
  72.    return self;
  73. }
  74.  
  75. - scaleHitWidthTo:(float)aScale
  76. {
  77.    NXPoint aPoint;
  78.  
  79.    aPoint.x = params[0] + hitWidth / 2;
  80.    aPoint.y = params[1] + hitWidth / 2;
  81.    hitWidth = officialHitWidth * (1.0 / aScale);
  82.    [self movePathToPoint:&aPoint];
  83.    return self;
  84. }
  85.              
  86. @end
  87.